<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
//require_once 'classes/DataBaseMysql.class.php';

Class BaseHospital {

	protected $m_intId;
	protected $m_strName;
	protected $m_strDescription;
	protected $m_strAddressLine1;
	protected $m_strAddressLine2;
	protected $m_strAddressLine3;
	protected $m_strArea;
	protected $m_strCity;
	protected $m_strPinCode;
	protected $m_strAddressDetails;
	protected $m_strPrimaryPhoneNumber;
	protected $m_strEmailAddress;
	protected $m_strWebUrl;
	protected $m_strAlternativeNumber;
	protected $connection;

	public function  __construct() {
		if( true == isset( $_SERVER['connection'] ) ) {
			$this->connection = $_SERVER['connection'];
		}
	}

	
	/*******************************************************************************************
	******************************** get Functions *********************************************
	*******************************************************************************************/

	public function getId(){
		return $this->m_intId;
	}

	public function getName(){
		return $this->m_strName;
	}

	public function getDescription(){
		return $this->m_strDescription;
	}

	public function getAddressLine1(){
		return $this->m_strAddressLine1;
	}

	public function getAddressLine2(){
		return $this->m_strAddressLine2;
	}

	public function getAddressLine3(){
		return $this->m_strAddressLine3;
	}

	public function getArea(){
		return $this->m_strArea;
	}

	public function getCity(){
		return $this->m_strCity;
	}

	public function getPinCode(){
		return $this->m_strPinCode;
	}

	public function getAddressDetails(){
		return $this->m_strAddressDetails;
	}

	public function getPrimaryPhoneNumber(){
		return $this->m_strPrimaryPhoneNumber;
	}

	public function getEmailAddress(){
		return $this->m_strEmailAddress;
	}

	public function getWebUrl(){
		return $this->m_strWebUrl;
	}

	public function getAlternativeNumber(){
		return $this->m_strAlternativeNumber;
	}
	
	/*******************************************************************************************
	********************************* set Functions ********************************************
	*******************************************************************************************/

	public function setId( $Id ){
		$this->m_intId = $Id;
	}

	public function setName( $Name ){
		$this->m_strName = $Name;
	}

	public function setDescription( $Description ){
		$this->m_strDescription = $Description;
	}

	public function setAddressLine1( $AddressLine1 ){
		$this->m_strAddressLine1 = $AddressLine1;
	}

	public function setAddressLine2( $AddressLine2 ){
		$this->m_strAddressLine2 = $AddressLine2;
	}

	public function setAddressLine3( $AddressLine3 ){
		$this->m_strAddressLine3 = $AddressLine3;
	}

	public function setArea( $Area ){
		$this->m_strArea = $Area;
	}

	public function setCity( $City ){
		$this->m_strCity = $City;
	}

	public function setPinCode( $PinCode ){
		$this->m_strPinCode = $PinCode;
	}

	public function setAddressDetails( $AddressDetails ){
		$this->m_strAddressDetails = $AddressDetails;
	}

	public function setPrimaryPhoneNumber( $PrimaryPhoneNumber ){
		$this->m_strPrimaryPhoneNumber = $PrimaryPhoneNumber;
	}

	public function setEmailAddress( $EmailAddress ){
		$this->m_strEmailAddress = $EmailAddress;
	}

	public function setWebUrl( $WebUrl ){
		$this->m_strWebUrl = $WebUrl;
	}

	public function setAlternativeNumber( $AlternativeNumber ){
		$this->m_strAlternativeNumber = $AlternativeNumber;
	}
	
	/*******************************************************************************************
	********************************* Insert Functions ********************************************
	*******************************************************************************************/

	public function insert(){
		return $this->connection->RunQuery( "Insert into HOSPITAL (name, description, address_line1, address_line2, address_line3, area, city, pin_code, address_details, primary_phone_number, email_address, web_url, alternative_number) values ('" . $this->getName() . "', '" . $this->getDescription() . "', '" . $this->getAddressLine1() . "', '" . $this->getAddressLine2() . "', '" . $this->getAddressLine3() . "', '" . $this->getArea() . "', '" . $this->getCity() . "', '" . $this->getPinCode() . "', '" . $this->getAddressDetails() . "', '" . $this->getPrimaryPhoneNumber() . "', '" . $this->getEmailAddress() . "', '" . $this->getWebUrl() . "', '" . $this->getAlternativeNumber() . "')");
	}
	
	/*******************************************************************************************
	********************************* Update Functions ********************************************
	*******************************************************************************************/

	public function update(){
		return $this->connection->RunQuery( "UPDATE HOSPITAL set  name= '" . $this->getName() . "', description= '" . $this->getDescription() . "', address_line1= '" . $this->getAddressLine1() . "', address_line2= '" . $this->getAddressLine2() . "', address_line3= '" . $this->getAddressLine3() . "', area= '" . $this->getArea() . "', city= '" . $this->getCity() . "', pin_code= '" . $this->getPinCode() . "', address_details= '" . $this->getAddressDetails() . "', primary_phone_number= '" . $this->getPrimaryPhoneNumber() . "', email_address= '" . $this->getEmailAddress() . "', web_url= '" . $this->getWebUrl() . "', alternative_number= '" . $this->getAlternativeNumber() . "' where id =" . $this->getId() );
	}
	
	/*******************************************************************************************
	********************************* Delete Functions ********************************************
	*******************************************************************************************/

	public function Delete($intId ) {
		$this->connection->RunQuery( "DELETE FROM hospital WHERE id = $intId");
	}

	public function fetchNextId() {
		$result = $this->connection->RunQuery( "SELECT AUTO_INCREMENT as id FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = 'hospital'" );
		if( false == $result ) return NULL;

		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$this->id = $row["id"];
		}

		return $this->id;
	}

}